extends Node

const FILE_FORMAT_PACKED_SCENE: String = '.tscn'
const FILE_FORMAT_GDSCRIPT: String = '.gd'

func _ready() -> void:
    pass

func get_files_in_directory(path_name: String, recursive: bool, result: Array, format: String) -> int:
    var dir: Directory = Directory.new()
    var file_number: int = 0
    if !path_name.ends_with('/'):
        path_name = path_name + '/'
    print(path_name)
    if dir.open(path_name) == OK:
        dir.list_dir_begin()
        var file_name = dir.get_next()
        while (file_name != ""):
            if dir.current_is_dir():
                if recursive == true:
                    if file_name != '.' and file_name != '..':
                        file_number = file_number + get_files_in_directory(path_name + file_name, true, result, format)
            elif file_name.ends_with(format):
                file_number = file_number + 1
                result.append(path_name + file_name)
            file_name = dir.get_next()
    else:
        print("我遇到一个难以理解的错误")
    return file_number
